home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume15 / monthtool2 / part02 < prev    next >
Encoding:
Internet Message Format  |  1988-06-01  |  45.5 KB

  1. Subject:  v15i028:  Monthly apointment calendar, for Suns, Part02/02
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: cognos!sarahm
  7. Posting-number: Volume 15, Issue 28
  8. Archive-name: monthtool/part02
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 2 (of 2)."
  17. # Contents:  monthtool.c
  18. # Wrapped by rsalz@fig.bbn.com on Thu Jun  2 15:04:55 1988
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. if test -f 'monthtool.c' -a "${1}" != "-c" ; then 
  21.   echo shar: Will not clobber existing file \"'monthtool.c'\"
  22. else
  23. echo shar: Extracting \"'monthtool.c'\" \(43509 characters\)
  24. sed "s/^X//" >'monthtool.c' <<'END_OF_FILE'
  25. X/*  @(#)monthtool.c    5.1 2/20/88 */
  26. X/*
  27. X    Name:        monthtool
  28. X  
  29. X    Purpose:     visual appointment calendar 
  30. X  
  31. X    Author:        Sarah Metcalfe apres Mike Essex & Rich Burridge
  32. X  
  33. X    Discussion: Displays a calendar to the screen for a given month.  
  34. X                User may move the mouse to any day of the
  35. X                month and view or enter appointments for that date. 
  36. X
  37. X    Modifications:
  38. X                10 Oct 87:    Sarah Metcalfe
  39. X                            Allow weekly appointments.
  40. X                            Automatically save on close and reload on open.
  41. X                            Automatically switch to today on open.
  42. X                 9 Nov 87:    D. Brent Chapman (capmkt!brent) 
  43. X                            Set the "DEFAULT_FONT" environment variable to 
  44. X                            the monthtool font, so that the program works 
  45. X                            properly under SunOS 3.4.
  46. X                25 Nov 87:    Steve Schlaifer (jplgodo!steve) 
  47. X                            Better fix for above problem.
  48. X                25 Nov 87:    Sarah Metcalfe 
  49. X                            Create half-shaded date boxes for days with only
  50. X                            yearly, monthly, weekly appts.
  51. X                20 Feb 88:    Sarah Metcalfe 
  52. X                            Fix message length bug (at least somewhat).
  53. X
  54. X*/
  55. X
  56. X
  57. X
  58. X
  59. X#include "monthtool.h"
  60. X
  61. static Notify_value     openCloseEvent();
  62. X
  63. void             dateEvent();
  64. X
  65. void             monthEvent();
  66. void             todayBtnHit();
  67. void             upBtnHit();
  68. void             downBtnHit();
  69. void             monthBackgroundHit();
  70. X
  71. void             notesBackgroundHit();
  72. void             notesPanelEvent();
  73. void             notesRadioHit();
  74. X
  75. Canvas             datesDsply;
  76. Textsw             notesDsply;
  77. Panel             monthPanel,
  78. X                 notesPanel;
  79. XFrame             frame;
  80. Menu             mainMenu,
  81. X                 fileMenu;
  82. Panel_item         monthItem,
  83. X                 notesTypeItem;
  84. Pixwin            *datesCrayon;
  85. struct pixfont     *font,
  86. X                *notesFont;
  87. X
  88. X
  89. short             dayIcon[] = {
  90. X    0xFFFF,0xFFFF,0xFF00,0x0000,0x8000,0x0000,0x0100,0x0000,
  91. X    0x8000,0x0000,0x0100,0x0000,0x8000,0x0000,0x0100,0x0000,
  92. X    0x8000,0x0000,0x0100,0x0000,0x8000,0x0000,0x0100,0x0000,
  93. X    0x8000,0x0000,0x0100,0x0000,0x8000,0x0000,0x0100,0x0000,
  94. X    0x8000,0x0000,0x0100,0x0000,0x8000,0x0000,0x0100,0x0000,
  95. X    0x8000,0x0000,0x0100,0x0000,0x8000,0x0000,0x0100,0x0000,
  96. X    0x8000,0x0000,0x0100,0x0000,0x8000,0x0000,0x0100,0x0000,
  97. X    0x8000,0x0000,0x0100,0x0000,0x8000,0x0000,0x0100,0x0000,
  98. X    0x8000,0x0000,0x0100,0x0000,0x8000,0x0000,0x0100,0x0000,
  99. X    0x8000,0x0000,0x0100,0x0000,0x8000,0x0000,0x0100,0x0000,
  100. X    0x8000,0x0000,0x0100,0x0000,0x8000,0x0000,0x0100,0x0000,
  101. X    0x8000,0x0000,0x0100,0x0000,0x8000,0x0000,0x0100,0x0000,
  102. X    0x8000,0x0000,0x0100,0x0000,0xFFFF,0xFFFF,0xFF00,0x0000,
  103. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  104. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  105. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  106. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  107. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  108. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  109. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  110. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  111. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  112. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  113. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  114. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  115. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  116. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  117. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  118. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  119. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  120. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  121. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
  122. X};
  123. mpr_static(dayPr, 64, 64, 1, dayIcon);
  124. X
  125. short             halfDayIcon[] = {
  126. X    0xFFFF,0xFFFF,0xFF00,0x0000,0x8000,0x0000,0x0100,0x0000,
  127. X    0xBFFF,0xFFFF,0xFD00,0x0000,0xA000,0x0000,0x0500,0x0000,
  128. X    0xA000,0x0000,0x0500,0x0000,0xA000,0x0000,0x0500,0x0000,
  129. X    0xA000,0x0000,0x0500,0x0000,0xA000,0x0000,0x0500,0x0000,
  130. X    0xA000,0x0000,0x0500,0x0000,0xA000,0x0000,0x0500,0x0000,
  131. X    0xA000,0x0000,0x0500,0x0000,0xA000,0x0000,0x0500,0x0000,
  132. X    0xA000,0x0000,0x0500,0x0000,0xA000,0x0000,0x0500,0x0000,
  133. X    0xA000,0x0000,0x0500,0x0000,0xA000,0x0000,0x0500,0x0000,
  134. X    0xA000,0x0000,0x0500,0x0000,0xA000,0x0000,0x0500,0x0000,
  135. X    0xA000,0x0000,0x0500,0x0000,0xA000,0x0000,0x0500,0x0000,
  136. X    0xA000,0x0000,0x0500,0x0000,0xA000,0x0000,0x0500,0x0000,
  137. X    0xA000,0x0000,0x0500,0x0000,0xBFFF,0xFFFF,0xFD00,0x0000,
  138. X    0x8000,0x0000,0x0100,0x0000,0xFFFF,0xFFFF,0xFF00,0x0000,
  139. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  140. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  141. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  142. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  143. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  144. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  145. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  146. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  147. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  148. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  149. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  150. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  151. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  152. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  153. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  154. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  155. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  156. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  157. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
  158. X};
  159. mpr_static(halfDayPr, 64, 64, 1, halfDayIcon);
  160. X
  161. short             fullDayIcon[] = {
  162. X    0xFFFF,0xFFFF,0xFF00,0x0000,0xFFFF,0xFFFF,0xFF00,0x0000,
  163. X    0xFFFF,0xFFFF,0xFF00,0x0000,0xE000,0x0000,0x0700,0x0000,
  164. X    0xE000,0x0000,0x0700,0x0000,0xE000,0x0000,0x0700,0x0000,
  165. X    0xE000,0x0000,0x0700,0x0000,0xE000,0x0000,0x0700,0x0000,
  166. X    0xE000,0x0000,0x0700,0x0000,0xE000,0x0000,0x0700,0x0000,
  167. X    0xE000,0x0000,0x0700,0x0000,0xE000,0x0000,0x0700,0x0000,
  168. X    0xE000,0x0000,0x0700,0x0000,0xE000,0x0000,0x0700,0x0000,
  169. X    0xE000,0x0000,0x0700,0x0000,0xE000,0x0000,0x0700,0x0000,
  170. X    0xE000,0x0000,0x0700,0x0000,0xE000,0x0000,0x0700,0x0000,
  171. X    0xE000,0x0000,0x0700,0x0000,0xE000,0x0000,0x0700,0x0000,
  172. X    0xE000,0x0000,0x0700,0x0000,0xE000,0x0000,0x0700,0x0000,
  173. X    0xE000,0x0000,0x0700,0x0000,0xFFFF,0xFFFF,0xFF00,0x0000,
  174. X    0xFFFF,0xFFFF,0xFF00,0x0000,0xFFFF,0xFFFF,0xFF00,0x0000,
  175. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  176. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  177. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  178. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  179. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  180. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  181. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  182. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  183. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  184. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  185. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  186. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  187. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  188. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  189. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  190. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  191. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  192. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  193. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
  194. X};
  195. mpr_static(fullDayPr, 64, 64, 1, fullDayIcon);
  196. X
  197. short             daySelIcon[] = {
  198. X    0xFFFF,0xFFFF,0xFF00,0x0000,0xA222,0x2222,0x2300,0x0000,
  199. X    0xC444,0x4444,0x4500,0x0000,0x9111,0x1111,0x1100,0x0000,
  200. X    0x8888,0x8888,0x8900,0x0000,0xA222,0x2222,0x2300,0x0000,
  201. X    0xC444,0x4444,0x4500,0x0000,0x9111,0x1111,0x1100,0x0000,
  202. X    0x8888,0x8888,0x8900,0x0000,0xA222,0x2222,0x2300,0x0000,
  203. X    0xC444,0x4444,0x4500,0x0000,0x9111,0x1111,0x1100,0x0000,
  204. X    0x8888,0x8888,0x8900,0x0000,0xA222,0x2222,0x2300,0x0000,
  205. X    0xC444,0x4444,0x4500,0x0000,0x9111,0x1111,0x1100,0x0000,
  206. X    0x8888,0x8888,0x8900,0x0000,0xA222,0x2222,0x2300,0x0000,
  207. X    0xC444,0x4444,0x4500,0x0000,0x9111,0x1111,0x1100,0x0000,
  208. X    0x8888,0x8888,0x8900,0x0000,0xA222,0x2222,0x2300,0x0000,
  209. X    0xC444,0x4444,0x4500,0x0000,0x9111,0x1111,0x1100,0x0000,
  210. X    0x8888,0x8888,0x8900,0x0000,0xFFFF,0xFFFF,0xFF00,0x0000,
  211. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  212. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  213. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  214. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  215. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  216. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  217. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  218. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  219. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  220. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  221. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  222. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  223. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  224. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  225. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  226. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  227. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  228. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  229. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
  230. X};
  231. mpr_static(daySelPr, 64, 64, 1, daySelIcon);
  232. X
  233. short             halfDaySelIcon[] = {
  234. X    0xFFFF,0xFFFF,0xFF00,0x0000,0x8000,0x0000,0x0100,0x0000,
  235. X    0xBFFF,0xFFFF,0xFD00,0x0000,0xB111,0x1111,0x1500,0x0000,
  236. X    0xA888,0x8888,0x8D00,0x0000,0xA222,0x2222,0x2500,0x0000,
  237. X    0xA444,0x4444,0x4500,0x0000,0xB111,0x1111,0x1500,0x0000,
  238. X    0xA888,0x8888,0x8D00,0x0000,0xA222,0x2222,0x2500,0x0000,
  239. X    0xA444,0x4444,0x4500,0x0000,0xB111,0x1111,0x1500,0x0000,
  240. X    0xA888,0x8888,0x8D00,0x0000,0xA222,0x2222,0x2500,0x0000,
  241. X    0xA444,0x4444,0x4500,0x0000,0xB111,0x1111,0x1500,0x0000,
  242. X    0xA888,0x8888,0x8D00,0x0000,0xA222,0x2222,0x2500,0x0000,
  243. X    0xA444,0x4444,0x4500,0x0000,0xB111,0x1111,0x1500,0x0000,
  244. X    0xA888,0x8888,0x8D00,0x0000,0xA222,0x2222,0x2500,0x0000,
  245. X    0xA444,0x4444,0x4500,0x0000,0xBFFF,0xFFFF,0xFD00,0x0000,
  246. X    0x8000,0x0000,0x0100,0x0000,0xFFFF,0xFFFF,0xFF00,0x0000,
  247. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  248. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  249. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  250. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  251. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  252. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  253. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  254. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  255. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  256. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  257. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  258. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  259. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  260. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  261. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  262. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  263. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  264. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  265. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
  266. X};
  267. mpr_static(halfDaySelPr, 64, 64, 1, halfDaySelIcon);
  268. X
  269. short             fullDaySelIcon[] = {
  270. X    0xFFFF,0xFFFF,0xFF00,0x0000,0xFFFF,0xFFFF,0xFF00,0x0000,
  271. X    0xFFFF,0xFFFF,0xFF00,0x0000,0xF111,0x1111,0x1700,0x0000,
  272. X    0xE888,0x8888,0x8F00,0x0000,0xE222,0x2222,0x2700,0x0000,
  273. X    0xE444,0x4444,0x4700,0x0000,0xF111,0x1111,0x1700,0x0000,
  274. X    0xE888,0x8888,0x8F00,0x0000,0xE222,0x2222,0x2700,0x0000,
  275. X    0xE444,0x4444,0x4700,0x0000,0xF111,0x1111,0x1700,0x0000,
  276. X    0xE888,0x8888,0x8F00,0x0000,0xE222,0x2222,0x2700,0x0000,
  277. X    0xE444,0x4444,0x4700,0x0000,0xF111,0x1111,0x1700,0x0000,
  278. X    0xE888,0x8888,0x8F00,0x0000,0xE222,0x2222,0x2700,0x0000,
  279. X    0xE444,0x4444,0x4700,0x0000,0xF111,0x1111,0x1700,0x0000,
  280. X    0xE888,0x8888,0x8F00,0x0000,0xE222,0x2222,0x2700,0x0000,
  281. X    0xE444,0x4444,0x4700,0x0000,0xFFFF,0xFFFF,0xFF00,0x0000,
  282. X    0xFFFF,0xFFFF,0xFF00,0x0000,0xFFFF,0xFFFF,0xFF00,0x0000,
  283. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  284. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  285. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  286. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  287. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  288. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  289. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  290. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  291. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  292. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  293. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  294. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  295. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  296. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  297. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  298. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  299. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  300. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  301. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
  302. X};
  303. mpr_static(fullDaySelPr, 64, 64, 1, fullDaySelIcon);
  304. X
  305. X
  306. short             upBtnIcon[] = {
  307. X    0x3FFF,0xE000,0x7FFF,0xF000,
  308. X    0xE000,0x3800,0xC000,0x1800,
  309. X    0xC020,0x1800,0xC070,0x1800,
  310. X    0xC0F8,0x1800,0xC1FC,0x1800,
  311. X    0xC3FE,0x1800,0xC7FF,0x1800,
  312. X    0xCFFF,0x9800,0xC0F8,0x1800,
  313. X    0xC0F8,0x1800,0xC0F8,0x1800,
  314. X    0xC0F8,0x1800,0xC000,0x1800,
  315. X    0xE000,0x3800,0x7FFF,0xF000,
  316. X    0x3FFF,0xE000,0x0000,0x0000
  317. X};
  318. mpr_static(upBtnPr, BTN_WIDTH, BTN_HEIGHT, 1, upBtnIcon);
  319. X
  320. short             downBtnIcon[] = {
  321. X    0x3FFF,0xE000,0x7FFF,0xF000,
  322. X    0xE000,0x3800,0xC000,0x1800,
  323. X    0xC0F8,0x1800,0xC0F8,0x1800,
  324. X    0xC0F8,0x1800,0xC0F8,0x1800,
  325. X    0xCFFF,0x9800,0xC7FF,0x1800,
  326. X    0xC3FE,0x1800,0xC1FC,0x1800,
  327. X    0xC0F8,0x1800,0xC070,0x1800,
  328. X    0xC020,0x1800,0xC000,0x1800,
  329. X    0xE000,0x3800,0x7FFF,0xF000,
  330. X    0x3FFF,0xE000,0x0000,0x0000
  331. X};
  332. mpr_static(downBtnPr, BTN_WIDTH, BTN_HEIGHT, 1, downBtnIcon);
  333. X
  334. X
  335. short             toolIcon[] = {
  336. X    0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8C08,0x87C2,0x21F0,0xF031,
  337. X    0x920D,0x8102,0x2040,0x8049,0x880A,0x8102,0xA040,0xE021,
  338. X    0x840A,0x8102,0xA040,0x8011,0x9208,0x8103,0x6040,0x8049,
  339. X    0x8C08,0x8102,0x2040,0x8031,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  340. X    0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8040,0x2010,0x0804,0x0201,
  341. X    0x8040,0x2814,0x0A05,0x0281,0x8040,0x2814,0x0A05,0x0281,
  342. X    0x8040,0x2010,0x0804,0x0201,0x8040,0x2010,0x0804,0x0201,
  343. X    0x8040,0x2013,0xA804,0x0201,0x8040,0x2010,0x0804,0x0201,
  344. X    0x8040,0x2016,0x8804,0x0201,0x8040,0x2010,0x0804,0x0201,
  345. X    0x8040,0x2010,0x0804,0x0201,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  346. X    0x8040,0x2010,0x0804,0x0201,0xA050,0x2814,0x0B05,0x82C1,
  347. X    0xA050,0x2814,0x0B05,0x82C1,0x8040,0x2010,0x0804,0x0201,
  348. X    0x8040,0x2010,0x0804,0x0201,0x8040,0x2010,0x0805,0xD201,
  349. X    0x8040,0x2010,0x0804,0x0201,0x8040,0x2010,0x0804,0x0201,
  350. X    0x8040,0x2010,0x0804,0x0201,0x8040,0x2010,0x0804,0x0201,
  351. X    0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8040,0x2010,0x0804,0x0201,
  352. X    0xB058,0x2C16,0x0B05,0x82C1,0xB058,0x2C16,0x0B05,0x82C1,
  353. X    0x8040,0x2010,0x0804,0x0201,0x8040,0x2F50,0x0804,0x0201,
  354. X    0x8040,0x2010,0x0804,0x0201,0x8040,0x2D50,0x0804,0x0201,
  355. X    0x8040,0x2010,0x0804,0x0201,0x8040,0x2010,0x0804,0x0201,
  356. X    0x8040,0x2010,0x0804,0x0201,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  357. X    0x8040,0x2010,0x0804,0x0201,0xB058,0x2C16,0x0B05,0x82C1,
  358. X    0xB058,0x2C16,0x0B05,0x82C1,0x8040,0x2010,0x0804,0x0201,
  359. X    0x8040,0x2010,0x0BE4,0x0201,0x8040,0x2010,0x0804,0x0201,
  360. X    0x8040,0x2010,0x0BA4,0x0201,0x8040,0x2010,0x0804,0x0201,
  361. X    0x8040,0x2010,0x0804,0x0201,0x8040,0x2010,0x0804,0x0201,
  362. X    0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8040,0x2010,0x0804,0x0201,
  363. X    0xB058,0x2C16,0x0B04,0x0201,0xB058,0x2C16,0x0B04,0x0201,
  364. X    0x8040,0x2010,0x0804,0x0201,0x8040,0x2010,0x0804,0x0201,
  365. X    0xBA40,0x2017,0xC804,0x0201,0x8040,0x2010,0x0804,0x0201,
  366. X    0x8040,0x2013,0xC804,0x0201,0x9240,0x2010,0x0804,0x0201,
  367. X    0x8040,0x2010,0x0804,0x0201,0xFFFF,0xFFFF,0xFFFF,0xFFFF
  368. X};
  369. DEFINE_ICON_FROM_IMAGE(monthIcon, toolIcon);
  370. X
  371. X
  372. X
  373. struct dateBox         monthBoxes[DATE_ROWS][DATE_COLS];
  374. X
  375. X
  376. struct apptsData     *firstApptRecord[NUM_NOTES_TYPE + 1 /*for NOTES_ERROR*/];
  377. struct apptsData     *lastApptRecord[NUM_NOTES_TYPE + 1 /*for NOTES_ERROR*/];
  378. X
  379. X    
  380. int                     tmonth, tday, tyear;
  381. int                     firstDow;
  382. X
  383. int                     yearToShow, monthToShow;
  384. int                     dayToShow = 0;
  385. int                     dateNumToShow[NUM_NOTES_TYPE];
  386. X
  387. int                     editCount = 0;
  388. int                     notesModified = 0;
  389. int                     hasWeeklyNotes;
  390. X
  391. char                 toolFile[80];
  392. struct stat             lastStatus;
  393. X
  394. char                 typeChar[NUM_NOTES_TYPE] = { 0x90, 0x91, 0x92, 0x93, 0x94 }; 
  395. char                 typeMark[3] = "  ";
  396. X                            
  397. char                *smon[] = { "January", "February", "March",
  398. X                                "April", "May", "June",
  399. X                                "July", "August", "September",
  400. X                                "October", "November", "December"
  401. X                              };
  402. int                     mon[] = { 0,     31, 29, 31, 
  403. X                                    30, 31, 30,
  404. X                                    31, 31, 30, 
  405. X                                    31, 30, 31, 
  406. X                              };
  407. X
  408. X
  409. main(argc, argv)
  410. X
  411. int         argc;
  412. char    *argv[];
  413. X
  414. X{
  415. X    char    fontString[80];
  416. X    char    choiceString[2];
  417. X    int        type;
  418. X
  419. X    /* set default font */
  420. X
  421. X    strcpy(fontString, FONTDIR);
  422. X    strcat(fontString, NORMALFONT);
  423. X
  424. X    font = pf_open(LARGEFONT);              /* Open large sized font. */
  425. X    notesFont = pf_open(fontString);        /* Open regular sized font. */
  426. X
  427. X    /* Set up menus */
  428. X                        
  429. X    fileMenu = menu_create(MENU_ITEM,
  430. X                                MENU_STRING,    "Save",
  431. X                                MENU_VALUE,         MENU_SAVE,
  432. X                                0,
  433. X                            MENU_ITEM,
  434. X                                MENU_STRING,    "Reload",
  435. X                                MENU_VALUE,         MENU_RELOAD,
  436. X                                0,
  437. X                            0);
  438. X
  439. X    mainMenu = menu_create(MENU_ITEM,
  440. X                                MENU_STRING,    "Close (with Save)",
  441. X                                MENU_VALUE,         MENU_CLOSE,
  442. X                                0,
  443. X                            MENU_ITEM,
  444. X                                MENU_STRING,    "Update Appts.",
  445. X                                MENU_PULLRIGHT,     fileMenu,
  446. X                                0,
  447. X                            MENU_ITEM,
  448. X                                MENU_STRING,    "Quit (with Save)",
  449. X                                MENU_VALUE,         MENU_QUIT,
  450. X                                0,
  451. X                            0);
  452. X                        
  453. X
  454. X    /*    Set up windows */
  455. X
  456. X    frame = window_create(0, FRAME,
  457. X                FRAME_ICON, &monthIcon,
  458. X                FRAME_SHOW_LABEL, FALSE,
  459. X                FRAME_SUBWINDOWS_ADJUSTABLE, FALSE,
  460. X                FRAME_NO_CONFIRM, FALSE,
  461. X                WIN_HEIGHT, DATES_HEIGHT + MONTH_HEIGHT + 
  462. X                    NOTES_PANEL_HEIGHT + NOTES_HEIGHT + 25,
  463. X                WIN_WIDTH, WINDOW_WIDTH + 10,
  464. X                FRAME_ARGS, argc, argv,
  465. X                0);
  466. X    (void) notify_interpose_event_func( frame, openCloseEvent, NOTIFY_SAFE );
  467. X
  468. X    monthPanel = window_create(frame, PANEL,
  469. X                WIN_X, 0,
  470. X                WIN_Y, 0,
  471. X                WIN_HEIGHT, MONTH_HEIGHT,
  472. X                WIN_WIDTH, WINDOW_WIDTH,
  473. X                WIN_FONT, font,
  474. X                PANEL_BACKGROUND_PROC, monthBackgroundHit,
  475. X                PANEL_EVENT_PROC, monthEvent,
  476. X                0);
  477. X
  478. X    datesDsply = window_create(frame, CANVAS,
  479. X                WIN_X, 0,
  480. X                WIN_BELOW, monthPanel,
  481. X                WIN_HEIGHT, DATES_HEIGHT,
  482. X                WIN_WIDTH, WINDOW_WIDTH,
  483. X                WIN_FONT, font,
  484. X                WIN_EVENT_PROC, dateEvent,
  485. X                WIN_CONSUME_KBD_EVENTS, WIN_ASCII_EVENTS, WIN_LEFT_KEYS, 0,
  486. X                0);
  487. X
  488. X    datesCrayon = canvas_pixwin(datesDsply);
  489. X
  490. X    notesPanel = window_create(frame, PANEL,
  491. X                WIN_X, 0,
  492. X                WIN_BELOW, datesDsply,
  493. X                WIN_HEIGHT, NOTES_PANEL_HEIGHT,
  494. X                WIN_WIDTH, WINDOW_WIDTH,
  495. X                WIN_FONT, notesFont,
  496. X                PANEL_BACKGROUND_PROC, notesBackgroundHit,
  497. X                PANEL_EVENT_PROC, notesPanelEvent,
  498. X                0);
  499. X
  500. X    notesDsply = window_create(frame, TEXTSW,
  501. X                WIN_X, 0,
  502. X                WIN_BELOW, notesPanel,
  503. X                WIN_HEIGHT, WIN_EXTEND_TO_EDGE,
  504. X                WIN_WIDTH, 10000 /* very large number, cuts to actual width */,
  505. X                WIN_FONT, notesFont,
  506. X                TEXTSW_IGNORE_LIMIT, TEXTSW_INFINITY,
  507. X                0);
  508. X    /* For bug in Sun Version 3.4 */
  509. X    window_set( notesDsply, WIN_FONT, notesFont, 0);
  510. X
  511. X    /* Set up panels */
  512. X
  513. X
  514. X    monthItem = panel_create_item(monthPanel, PANEL_MESSAGE,
  515. X                    PANEL_LABEL_X, 5,
  516. X                    PANEL_LABEL_Y, 10,
  517. X                  0);
  518. X                        
  519. X
  520. X    panel_create_item( monthPanel, PANEL_BUTTON,
  521. X                        PANEL_ITEM_X, WINDOW_WIDTH - 2 * (BTN_WIDTH + GAP) - 55,
  522. X                        PANEL_ITEM_Y, 10,
  523. X                          PANEL_NOTIFY_PROC, todayBtnHit, 
  524. X                           PANEL_LABEL_IMAGE,
  525. X                            panel_button_image(monthPanel,"Today",0,notesFont),
  526. X                        0);
  527. X
  528. X    panel_create_item( monthPanel, PANEL_BUTTON,
  529. X                        PANEL_ITEM_X, WINDOW_WIDTH - 2 * (BTN_WIDTH + GAP),
  530. X                        PANEL_ITEM_Y, 10,
  531. X                          PANEL_NOTIFY_PROC, upBtnHit, 
  532. X                           PANEL_LABEL_IMAGE, &upBtnPr,
  533. X                        0);
  534. X
  535. X    panel_create_item( monthPanel, PANEL_BUTTON,
  536. X                        PANEL_ITEM_X, WINDOW_WIDTH - (BTN_WIDTH + GAP),
  537. X                        PANEL_ITEM_Y, 10,
  538. X                          PANEL_NOTIFY_PROC, downBtnHit, 
  539. X                           PANEL_LABEL_IMAGE, &downBtnPr,
  540. X                        0);
  541. X
  542. X
  543. X    notesTypeItem = panel_create_item( notesPanel, PANEL_CHOICE,
  544. X                        PANEL_LABEL_STRING, "Reminder Types:",
  545. X                        PANEL_FEEDBACK, PANEL_NONE,
  546. X                        PANEL_NOTIFY_PROC, notesRadioHit,
  547. X                    0);
  548. X    choiceString[1] = '\0';
  549. X    for (type = 0; type < NUM_NOTES_TYPE; type++) {
  550. X        choiceString[0] = typeChar[type];
  551. X        panel_set( notesTypeItem, PANEL_CHOICE_STRING, type, choiceString, 0);
  552. X        panel_set( notesTypeItem, PANEL_CHOICE_X, type, 100 + 35*(type+1), 0);
  553. X        panel_set( notesTypeItem, PANEL_CHOICE_Y, type, 4, 0);
  554. X    }
  555. X    panel_set( notesTypeItem, PANEL_LABEL_X, 4, 0);
  556. X    panel_set( notesTypeItem, PANEL_LABEL_Y, 4, 0);
  557. X
  558. X    /* Get monthtool filename */
  559. X
  560. X    strcpy(toolFile, getenv("HOME"));
  561. X    strcat(toolFile, "/.monthtool");
  562. X
  563. X    /* Get today's date */
  564. X
  565. X    todaySet();
  566. X    yearToShow = tyear;
  567. X    monthToShow = tmonth;
  568. X
  569. X    /* Load the appointments file and show this month's calendar */
  570. X    
  571. X    loadData();    
  572. X    firstDowSet();
  573. X    dayHit(tday);    
  574. X
  575. X    /* Wait for events */
  576. X
  577. X    window_main_loop(frame);
  578. X
  579. X    /* When done, leave */
  580. X
  581. X    freeData();
  582. X    exit(0);
  583. X
  584. X}
  585. X
  586. static Notify_value    openCloseEvent(frame, event, arg, type)
  587. X
  588. XFrame                 frame;
  589. XEvent                *event;
  590. Notify_arg             arg;
  591. Notify_event_type     type;
  592. X
  593. X{
  594. X    int                    initialClosed, finalClosed;
  595. X    Notify_value        value;
  596. X
  597. X    initialClosed = (int) window_get( frame, FRAME_CLOSED );
  598. X    value = notify_next_event_func( frame, event, arg, type );
  599. X    finalClosed = (int) window_get( frame, FRAME_CLOSED );
  600. X
  601. X    if ( initialClosed != finalClosed ) {
  602. X        if ( finalClosed ) {
  603. X            saveData();
  604. X        }else{
  605. X            reloadData();
  606. X            todaySet();
  607. X            monthToShow = tmonth;
  608. X            yearToShow = tyear;
  609. X            monthDisplay();
  610. X            dayHit(tday);
  611. X        }
  612. X    }
  613. X
  614. X    return( value );
  615. X        
  616. X}
  617. X
  618. static void    monthEvent(item, event)
  619. X
  620. Panel_item     item;
  621. XEvent        *event;
  622. X
  623. X{
  624. X    switch (event_id(event)) {
  625. X    case MS_RIGHT:
  626. X        if (event_is_down(event)) {
  627. X            rootMenuDisplay(monthPanel,event);
  628. X        }
  629. X        break;
  630. X    case MS_LEFT:
  631. X        panel_default_handle_event(item,event);
  632. X        break;
  633. X    default:
  634. X        return;
  635. X    }
  636. X
  637. X}
  638. X
  639. static void    todayBtnHit(item, event)
  640. X
  641. Panel_item     item;
  642. XEvent        *event;
  643. X
  644. X{
  645. X    todaySet();
  646. X    if ( (monthToShow != tmonth) || (yearToShow != tyear) ) {
  647. X        notesSave();
  648. X        monthToShow = tmonth;
  649. X        yearToShow = tyear;
  650. X        monthDisplay();
  651. X        dayHit(tday);
  652. X    }else{
  653. X        if (dayToShow != tday) {
  654. X            notesSave();
  655. X            dayHit(tday);
  656. X        }
  657. X    }
  658. X}
  659. X
  660. static void    upBtnHit(item, event)
  661. X
  662. Panel_item     item;
  663. XEvent        *event;
  664. X
  665. X{
  666. X    notesSave();
  667. X    if (--monthToShow < 1) {
  668. X        monthToShow = 12;
  669. X        yearToShow--;
  670. X    }
  671. X    monthDisplay();
  672. X    dayHit(1);
  673. X
  674. X}
  675. X
  676. static void    downBtnHit(item, event)
  677. X
  678. Panel_item     item;
  679. XEvent        *event;
  680. X
  681. X{
  682. X    notesSave();
  683. X    if (++monthToShow == 13) {
  684. X        monthToShow = 1;
  685. X        yearToShow++;
  686. X    }
  687. X    monthDisplay();
  688. X    dayHit(1);
  689. X
  690. X}
  691. X
  692. static void    monthBackgroundHit(panel, event)
  693. X
  694. Panel         panel;
  695. XEvent        *event;
  696. X
  697. X{
  698. X    switch (event_id(event)) {
  699. X    case MS_RIGHT:
  700. X        if (event_is_down(event)) {
  701. X            rootMenuDisplay(monthPanel,event);
  702. X        }
  703. X        break;
  704. X    default:
  705. X        return;
  706. X    }
  707. X
  708. X}
  709. X
  710. static void    dateEvent(win, event, arg)
  711. X
  712. Canvas         win;
  713. XEvent        *event;
  714. caddr_t         arg;
  715. X
  716. X{
  717. X    int            column,
  718. X                row;
  719. X
  720. X    if (event_is_up(event)) {
  721. X        return;
  722. X    }
  723. X
  724. X    switch (event_id(event)) {
  725. X    case MS_LEFT:
  726. X        notesSave();
  727. X        column = event_x(event) / (DATE_BOX_WIDTH + GAP);
  728. X        row = (event_y(event)) / (DATE_BOX_HEIGHT + GAP);
  729. X        dayHit(monthBoxes[row][column].date);
  730. X        break;
  731. X    case MS_RIGHT:
  732. X        rootMenuDisplay(win,event);
  733. X        break;
  734. X    case WIN_REPAINT:
  735. X        notesSave();
  736. X        monthDisplay();
  737. X        dayHit(dayToShow);
  738. X        break;
  739. X    default:
  740. X        return;
  741. X    }
  742. X
  743. X}
  744. X
  745. dayHit(date)
  746. X
  747. int    date;
  748. X
  749. X{
  750. X    int                     row,
  751. X                         column;
  752. X    if (date != 0) {
  753. X        if (dayToShow != 0) {
  754. X            for (row = 0; row < DATE_ROWS; row++) {
  755. X                for (column = 0; column < DATE_COLS; column++) {
  756. X                    if (dayToShow == monthBoxes[row][column].date) {
  757. X                        dateBoxDisplay(row, column, NOHIGHLIGHT);
  758. X                    }
  759. X                }
  760. X            }
  761. X        }
  762. X        for (row = 0; row < DATE_ROWS; row++) {
  763. X            for (column = 0; column < DATE_COLS; column++) {
  764. X                if (date == monthBoxes[row][column].date) {
  765. X                    dateBoxDisplay(row, column, HIGHLIGHT);
  766. X                }
  767. X            }
  768. X        }
  769. X
  770. X        dayToShow = date;
  771. X
  772. X        dateNumToShow[NOTES_ALL_ALL_ALL] = 0;
  773. X
  774. X        dateNumToShow[NOTES_D_ALL_ALL] = dayToShow;
  775. X
  776. X        dateNumToShow[NOTES_D_M_ALL] = dayToShow + 100 * monthToShow;
  777. X
  778. X        dateNumToShow[NOTES_WEEKLY] = ((dayToShow + firstDow) % DATE_COLS);        
  779. X        if ( dateNumToShow[NOTES_WEEKLY] == 0 ) {
  780. X            dateNumToShow[NOTES_WEEKLY] = DATE_COLS;
  781. X        }
  782. X        dateNumToShow[NOTES_WEEKLY] += 100 * 99;
  783. X
  784. X        dateNumToShow[NOTES_D_M_Y] = dayToShow + 100 * monthToShow + 10000 * yearToShow;
  785. X
  786. X        notesDisplay();
  787. X
  788. X    }
  789. X
  790. X}
  791. X
  792. static void    notesPanelEvent(item, event)
  793. X
  794. Panel_item     item;
  795. XEvent        *event;
  796. X
  797. X{
  798. X
  799. X    switch (event_id(event)) {
  800. X    case MS_RIGHT:
  801. X        if (event_is_down(event)) {
  802. X            rootMenuDisplay(notesPanel,event);
  803. X        }
  804. X        break;
  805. X    case MS_LEFT:
  806. X        panel_default_handle_event(item,event);
  807. X        break;
  808. X    default:
  809. X        return;
  810. X    }
  811. X
  812. X}
  813. X
  814. static void    notesRadioHit(item, value, event)
  815. X
  816. Panel_item     item;
  817. int             value;
  818. XEvent        *event;
  819. X
  820. X{
  821. X    int            caretIndex,
  822. X                endIndex,
  823. X                lineStartIndex,
  824. X                nextLineStartIndex,
  825. X                ptrnStartIndex,
  826. X                ptrnEndIndex,
  827. X                ptrnLen,
  828. X                type,
  829. X                result,
  830. X                lineNo;
  831. X
  832. X    typeMark[0] = typeChar[value];
  833. X    ptrnLen = strlen(typeMark);
  834. X
  835. X    caretIndex = (int)window_get( notesDsply, TEXTSW_INSERTION_POINT );
  836. X
  837. X    lineNo = 0;
  838. X    lineStartIndex = 0;
  839. X    while (1) {
  840. X        nextLineStartIndex = (int)textsw_index_for_file_line(notesDsply, lineNo+1);
  841. X        if ( (nextLineStartIndex < 0) || (nextLineStartIndex > caretIndex) ) {
  842. X            break;
  843. X        }
  844. X        lineNo++;
  845. X        lineStartIndex = nextLineStartIndex;
  846. X    }
  847. X
  848. X    window_set( notesDsply, TEXTSW_INSERTION_POINT, lineStartIndex, 0 );
  849. X    textsw_insert( notesDsply, typeMark, ptrnLen );
  850. X    caretIndex += ptrnLen;
  851. X
  852. X    endIndex = (int)window_get( notesDsply, TEXTSW_LENGTH );
  853. X    if ( (nextLineStartIndex < 0) || (nextLineStartIndex > endIndex) ) {
  854. X        nextLineStartIndex = endIndex + 1;
  855. X    }
  856. X    
  857. X    lineStartIndex += strlen(typeMark);
  858. X    for (type = 0; type < NUM_NOTES_TYPE; type++) {
  859. X
  860. X        typeMark[0] = typeChar[type];
  861. X        ptrnLen = strlen(typeMark);
  862. X        while ( ptrnLen ) {
  863. X            do {
  864. X                ptrnStartIndex = lineStartIndex;
  865. X                result = textsw_find_bytes(notesDsply, &ptrnStartIndex, &ptrnEndIndex,
  866. X                    typeMark, ptrnLen, 0);
  867. X                if (result != -1) {
  868. X                    if ((ptrnEndIndex < nextLineStartIndex) && (ptrnStartIndex >= lineStartIndex)) {
  869. X                        textsw_erase(notesDsply, ptrnStartIndex, ptrnEndIndex);
  870. X                        caretIndex -= ptrnLen;
  871. X                    }else{
  872. X                        result = -1;
  873. X                    }
  874. X                }
  875. X            } while (result != -1);
  876. X            ptrnLen--;
  877. X        }
  878. X            
  879. X    }
  880. X
  881. X    window_set( notesDsply, TEXTSW_INSERTION_POINT, caretIndex, 0);
  882. X
  883. X}
  884. X
  885. static void    notesBackgroundHit(panel, event)
  886. X
  887. Panel         panel;
  888. XEvent        *event;
  889. X
  890. X{
  891. X    switch (event_id(event)) {
  892. X    case MS_RIGHT:
  893. X        if (event_is_down(event)) {
  894. X            rootMenuDisplay(notesPanel,event);
  895. X        }
  896. X        break;
  897. X    default:
  898. X        return;
  899. X    }
  900. X
  901. X}
  902. X
  903. rootMenuDisplay(window, event)
  904. X
  905. Window         window;
  906. XEvent        *event;
  907. X
  908. X{
  909. X
  910. X    switch( (int)menu_show(mainMenu, window, event, 0) ) {
  911. X    case MENU_SAVE:
  912. X        saveData();
  913. X        break;
  914. X    case MENU_RELOAD:
  915. X        reloadData();
  916. X        monthDisplay();
  917. X        dayHit(dayToShow);
  918. X        break;
  919. X    case MENU_CLOSE:
  920. X        saveData();
  921. X        window_set(frame, FRAME_CLOSED, TRUE, 0);
  922. X        break;
  923. X    case MENU_QUIT:
  924. X        saveData();
  925. X        window_destroy(frame);
  926. X        break;
  927. X    }
  928. X
  929. X}
  930. X
  931. monthDisplay()
  932. X
  933. X
  934. X{                
  935. X    int                     column,
  936. X                         row;
  937. X    int                     i, day;
  938. X    char                 monthString[20];
  939. X    struct apptsData     *cur ;
  940. X    struct dateBox        *thisBox;
  941. X
  942. X    sprintf(monthString, "%s %4u", smon[monthToShow-1], yearToShow);
  943. X    panel_set(monthItem, PANEL_LABEL_STRING, monthString, 0);
  944. X
  945. X    firstDowSet();
  946. X
  947. X    row = 0;
  948. X    for (column = 0; column < firstDow; column++) {
  949. X        monthBoxes[row][column].date = 0;
  950. X        monthBoxes[row][column].boxOutline = NO_OUTLINE;
  951. X    }
  952. X
  953. X    for ( day = 1; day <= mon[monthToShow]; day++) {
  954. X        monthBoxes[row][column].date = day;
  955. X        monthBoxes[row][column].boxOutline = NO_OUTLINE;
  956. X        if (column >= (DATE_COLS-1)) {
  957. X            row++;
  958. X            column = 0;
  959. X        }else{
  960. X            column++;
  961. X        }
  962. X    }
  963. X
  964. X    for (; row < DATE_ROWS; row++) {
  965. X        for (; column < DATE_COLS; column++) {
  966. X            monthBoxes[row][column].date = 0;
  967. X            monthBoxes[row][column].boxOutline = NO_OUTLINE;
  968. X        }
  969. X        column = 0;        
  970. X    }
  971. X
  972. X    for (i = 0; i < NUM_NOTES_TYPE; i++) {
  973. X        if  ( i == NOTES_WEEKLY ) { 
  974. X            for ( cur = firstApptRecord[i]; cur != NULL; cur = cur->next) {
  975. X                if ( cur->month == 99 ) {
  976. X                    for (row = 0; row < DATE_ROWS; row++) {
  977. X                        if (monthBoxes[row][cur->day-1].boxOutline != FULL_OUTLINE) {
  978. X                            monthBoxes[row][cur->day-1].boxOutline = HALF_OUTLINE;
  979. X                         }
  980. X                     }
  981. X                }
  982. X            }
  983. X        }else if  ( i != NOTES_ALL_ALL_ALL ) {  
  984. X            for (cur = firstApptRecord[i]; cur != NULL; cur = cur->next) {
  985. X                if (    i==NOTES_D_ALL_ALL ||
  986. X                (             cur->month==monthToShow &&  
  987. X                (                 i==NOTES_D_M_ALL ||
  988. X                (                     cur->year==yearToShow 
  989. X                )))) { 
  990. X                    thisBox = &monthBoxes[(cur->day + firstDow-1) / DATE_COLS]
  991. X                                         [(cur->day + firstDow-1) % DATE_COLS];
  992. X                    if ( i == NOTES_D_M_Y ) {
  993. X                        thisBox->boxOutline = FULL_OUTLINE;
  994. X                    }else if ( i != NOTES_ALL_ALL_ALL ) {
  995. X                        if (thisBox->boxOutline != FULL_OUTLINE) {
  996. X                            thisBox->boxOutline = HALF_OUTLINE;
  997. X                        }
  998. X                    }
  999. X                }
  1000. X            }
  1001. X        }
  1002. X    }
  1003. X
  1004. X    pw_writebackground(datesCrayon, 0, 0, WINDOW_WIDTH, DATES_HEIGHT, PIX_CLR);
  1005. X
  1006. X    for (row = 0; row < DATE_ROWS; row++) {
  1007. X        for (column = 0; column < DATE_COLS; column++) {
  1008. X            dateBoxDisplay(row, column, NOHIGHLIGHT);
  1009. X        }
  1010. X    }
  1011. X
  1012. X}
  1013. X
  1014. firstDowSet()
  1015. X
  1016. X{
  1017. X    int            i;
  1018. X
  1019. X    firstDow = jan1Set(yearToShow);
  1020. X    mon[2] = 29;
  1021. X    mon[9] = 30;
  1022. X    switch ((jan1Set(yearToShow + 1) + 7 - firstDow) % 7) {
  1023. X    case 1:                /* non-leap year */
  1024. X        mon[2] = 28;
  1025. X        break;
  1026. X    case 2:                /* leap year */
  1027. X        break;
  1028. X    default:            /* 1752 */
  1029. X        mon[9] = 19;
  1030. X        break;
  1031. X    }
  1032. X    for (i = 1; i < monthToShow; i++) {    
  1033. X        firstDow += mon[i];
  1034. X    }
  1035. X    firstDow %= 7;
  1036. X
  1037. X}
  1038. X
  1039. X
  1040. X
  1041. X
  1042. X
  1043. jan1Set(year)
  1044. X
  1045. int             year;
  1046. X
  1047. X{
  1048. X
  1049. X    register        y, dow;
  1050. X
  1051. X    /* normal gregorian calendar one extra day per four years */
  1052. X
  1053. X    y = year;
  1054. X    dow = 4 + y + (y + 3) / 4;
  1055. X
  1056. X    /* julian calendar regular gregorian less three days per 400 */
  1057. X
  1058. X    if (y > 1800) {
  1059. X        dow -= (y - 1701) / 100;
  1060. X        dow += (y - 1601) / 400;
  1061. X    }
  1062. X
  1063. X    /* great calendar changeover instant */
  1064. X
  1065. X    if (y > 1752)
  1066. X        dow += 3;
  1067. X
  1068. X    return (dow % 7);
  1069. X
  1070. X} 
  1071. X
  1072. todaySet()
  1073. X
  1074. X
  1075. X{
  1076. X    struct tm      *tp;        /* time structure */
  1077. X    long            tloc;    /* number of seconds since 1970 */
  1078. X
  1079. X    time(&tloc);        
  1080. X    tp = localtime(&tloc);
  1081. X    tyear = tp->tm_year;
  1082. X    tmonth = tp->tm_mon + 1;
  1083. X    tday = tp->tm_mday;
  1084. X    tyear += 1900;
  1085. X
  1086. X}
  1087. X
  1088. dateBoxDisplay(row, column, hilite)
  1089. X
  1090. int              row;
  1091. int              column;
  1092. int              hilite;
  1093. X
  1094. X{
  1095. X    char            dateString[4];
  1096. X
  1097. X    if (monthBoxes[row][column].date == 0) {
  1098. X        pw_write(datesCrayon, 
  1099. X            column * DATE_BOX_WIDTH + DATE_BORDER + (column * GAP),
  1100. X            row * DATE_BOX_HEIGHT + DATE_BORDER + (row * GAP),
  1101. X            DATE_BOX_WIDTH, DATE_BOX_HEIGHT, PIX_SRC, &dayPr, 0, 0);
  1102. X        pw_text(datesCrayon, 
  1103. X            column * DATE_BOX_WIDTH + DATE_BORDER + (column * GAP) + 8,
  1104. X            row * DATE_BOX_HEIGHT + DATE_BORDER + (row * GAP) + 20,
  1105. X            PIX_SRC | PIX_DST, font, "  ");
  1106. X    }else{
  1107. X        switch (monthBoxes[row][column].boxOutline) {
  1108. X        case FULL_OUTLINE:
  1109. X            pw_write(datesCrayon, 
  1110. X                column * DATE_BOX_WIDTH + DATE_BORDER + (column * GAP),
  1111. X                row * DATE_BOX_HEIGHT + DATE_BORDER + (row * GAP),
  1112. X                DATE_BOX_WIDTH, DATE_BOX_HEIGHT, PIX_SRC, 
  1113. X                hilite ? &fullDaySelPr : &fullDayPr, 
  1114. X                0, 0);
  1115. X            break;
  1116. X        case HALF_OUTLINE:
  1117. X            pw_write(datesCrayon, 
  1118. X                column * DATE_BOX_WIDTH + DATE_BORDER + (column * GAP),
  1119. X                row * DATE_BOX_HEIGHT + DATE_BORDER + (row * GAP),
  1120. X                DATE_BOX_WIDTH, DATE_BOX_HEIGHT, PIX_SRC, 
  1121. X                hilite ? &halfDaySelPr : &halfDayPr, 
  1122. X                0, 0);
  1123. X            break;
  1124. X        case NO_OUTLINE:
  1125. X            pw_write(datesCrayon, 
  1126. X                column * DATE_BOX_WIDTH + DATE_BORDER + (column * GAP),
  1127. X                row * DATE_BOX_HEIGHT + DATE_BORDER + (row * GAP),
  1128. X                DATE_BOX_WIDTH, DATE_BOX_HEIGHT, PIX_SRC, 
  1129. X                hilite ? &daySelPr : &dayPr, 
  1130. X                0, 0);
  1131. X            break;
  1132. X        }
  1133. X        sprintf(dateString, "%2u", monthBoxes[row][column].date);
  1134. X        pw_text(datesCrayon, 
  1135. X            column * DATE_BOX_WIDTH + DATE_BORDER + (column * GAP) + 8,
  1136. X            row * DATE_BOX_HEIGHT + DATE_BORDER + (row * GAP) + 20,
  1137. X            PIX_SRC | PIX_DST, font, dateString);
  1138. X    }
  1139. X
  1140. X}
  1141. X
  1142. notesDisplay()
  1143. X
  1144. X
  1145. X{
  1146. X    int                     type,
  1147. X                          i;
  1148. X    char                 timeString[7];
  1149. X    struct apptsData     *cur;
  1150. X
  1151. X    hasWeeklyNotes = 0;
  1152. X
  1153. X    i = (int)window_get(notesDsply, TEXTSW_LENGTH);
  1154. X    if ( i > 0 ) {
  1155. X        textsw_erase( notesDsply, 0, i + 1 );
  1156. X    }
  1157. X
  1158. X    for (type = 0; type < NUM_NOTES_TYPE; type++) {
  1159. X
  1160. X        typeMark[0] = typeChar[type];
  1161. X
  1162. X        cur = firstApptRecord[type];
  1163. X        while ( (cur != NULL) && (cur->dateNum < dateNumToShow[type]) ) {
  1164. X            cur = cur->next;                    
  1165. X        }
  1166. X
  1167. X        while ( (cur != NULL) && (cur->dateNum == dateNumToShow[type]) ) {
  1168. X            
  1169. X            textsw_insert( notesDsply, typeMark, 2 );
  1170. X            if (cur->time != 0) {
  1171. X                sprintf(timeString, "%d:%02d ", 
  1172. X                    (int)(cur->time / 100), (cur->time % 100));
  1173. X                textsw_insert( notesDsply, timeString, strlen(timeString) );
  1174. X            }
  1175. X            textsw_insert( notesDsply, cur->apptMsg, strlen(cur->apptMsg) );
  1176. X            textsw_insert( notesDsply, "\n", 1 );
  1177. X            cur = cur->next;    
  1178. X            if ( type == NOTES_WEEKLY ) {                
  1179. X                hasWeeklyNotes = 1;
  1180. X            }
  1181. X
  1182. X        }
  1183. X    
  1184. X    }
  1185. X
  1186. X    editCount = (int)window_get(notesDsply, TEXTSW_EDIT_COUNT);
  1187. X    window_set(notesDsply, TEXTSW_FIRST_LINE, 0, 0);
  1188. X    window_set(notesDsply, TEXTSW_UPDATE_SCROLLBAR, 0);
  1189. X
  1190. X}
  1191. X
  1192. notesSave()
  1193. X
  1194. X
  1195. X{
  1196. X    int                     bufLen,
  1197. X                         row, column,
  1198. X                         notesFound,
  1199. X                         nowHasWeeklyNotes,
  1200. X                         type,
  1201. X                         newEditCount,
  1202. X                         thisTime, thisYear, thisMonth, thisDay;
  1203. X    char                *thisMsg,
  1204. X                        *untypedMsg,
  1205. X                        *notesBuffer;
  1206. X    struct apptsData     *cur,
  1207. X                        *new,
  1208. X                        *old,
  1209. X                        *nextAppt[NUM_NOTES_TYPE];
  1210. X
  1211. X    newEditCount = (int)window_get(notesDsply, TEXTSW_EDIT_COUNT);
  1212. X    if (newEditCount <= editCount) {
  1213. X        return;
  1214. X    }
  1215. X    editCount = newEditCount;
  1216. X
  1217. X    for (type = 0; type < NUM_NOTES_TYPE; type++) {
  1218. X
  1219. X        cur = firstApptRecord[type];
  1220. X        while ( (cur != NULL) && (cur->dateNum < dateNumToShow[type]) ) {
  1221. X            cur = cur->next;                    
  1222. X        }
  1223. X
  1224. X        while ( (cur != NULL) && (cur->dateNum == dateNumToShow[type]) ) {
  1225. X            if (cur->prev != NULL) {
  1226. X                cur->prev->next = cur->next;
  1227. X            }else{
  1228. X                firstApptRecord[type] = cur->next;
  1229. X            }
  1230. X            if (cur->next != NULL) {
  1231. X                cur->next->prev = cur->prev;
  1232. X            }else{
  1233. X                lastApptRecord[type] = cur->prev;
  1234. X            }
  1235. X            old = cur;        
  1236. X            cur = cur->next;        
  1237. X            free(old->apptMsg);
  1238. X            free(old);            
  1239. X        }
  1240. X        nextAppt[type] = cur;
  1241. X
  1242. X    }
  1243. X
  1244. X    notesFound = NO_OUTLINE;
  1245. X    nowHasWeeklyNotes = 0;
  1246. X    bufLen = (int)window_get(notesDsply, TEXTSW_LENGTH);
  1247. X    
  1248. X    if (bufLen > 0) {
  1249. X
  1250. X        notesBuffer = (char *)malloc( bufLen + 1 );
  1251. X        if ( notesBuffer == (char *)0 ) {
  1252. X            fprintf(stderr, "Monthtool error:  Out of memory.\n");
  1253. X            exit(4);
  1254. X        }
  1255. X        window_get( notesDsply, TEXTSW_CONTENTS, 0, notesBuffer, bufLen + 1 );
  1256. X    
  1257. X        thisMsg = strtok( notesBuffer, "\n" );
  1258. X
  1259. X        while ( thisMsg != NULL ) {
  1260. X    
  1261. X            stripType(thisMsg, &untypedMsg, &type);
  1262. X            findTime(&untypedMsg, &thisTime);
  1263. X                
  1264. X            if (strlen (untypedMsg) != 0) {
  1265. X
  1266. X                thisYear = thisMonth = thisDay = 0;
  1267. X                switch (type) {
  1268. X                    case NOTES_D_M_Y:
  1269. X                        thisYear = yearToShow;
  1270. X                    case NOTES_D_M_ALL:
  1271. X                        thisMonth = monthToShow;
  1272. X                    case NOTES_D_ALL_ALL:
  1273. X                        thisDay = dayToShow;
  1274. X                        break;
  1275. X                    case NOTES_WEEKLY:
  1276. X                        thisMonth = 99;
  1277. X                        thisDay = (dayToShow + firstDow) % DATE_COLS;
  1278. X                        if ( thisDay == 0 ) {
  1279. X                            thisDay = DATE_COLS;
  1280. X                        }
  1281. X                        nowHasWeeklyNotes = 1;
  1282. X                }
  1283. X
  1284. X                new = (struct apptsData *)malloc( sizeof( struct apptsData ) );
  1285. X                if ( new == (struct apptsData *)0 ) {
  1286. X                    fprintf(stderr, "Monthtool error:  Out of memory.\n");
  1287. X                    exit(4);
  1288. X                }
  1289. X                new->year = thisYear;
  1290. X                new->month = thisMonth;
  1291. X                new->day = thisDay;
  1292. X                new->dateNum = dateNumToShow[type];
  1293. X                new->time = thisTime;
  1294. X                new->apptMsg = (char *)malloc( strlen(untypedMsg) + 1 );
  1295. X                if ( new->apptMsg  == (char *)0 ) {
  1296. X                    fprintf(stderr, "Monthtool error:  Out of memory.\n");
  1297. X                    exit(4);
  1298. X                }
  1299. X                strcpy( new->apptMsg, untypedMsg );
  1300. X
  1301. X                if (nextAppt[type] != NULL) {
  1302. X                    new->prev = nextAppt[type]->prev;
  1303. X                    if (new->prev != NULL) {
  1304. X                        new->prev->next = new;
  1305. X                    }else{
  1306. X                        firstApptRecord[type] = new;
  1307. X                    }                
  1308. X                    new->next = nextAppt[type];
  1309. X                    if (new->next != NULL) {
  1310. X                        new->next->prev = new;
  1311. X                    }else{
  1312. X                        lastApptRecord[type] = new;
  1313. X                    }                
  1314. X                }else{    
  1315. X                    if ( lastApptRecord[type] != NULL ) {
  1316. X                        new->next = NULL;
  1317. X                        new->prev = lastApptRecord[type];
  1318. X                        lastApptRecord[type]->next = new;
  1319. X                        lastApptRecord[type] = new;
  1320. X                    }else{                
  1321. X                        firstApptRecord[type] = lastApptRecord[type] = new;
  1322. X                        new->prev = new->next = NULL;
  1323. X                    }
  1324. X                }    
  1325. X    
  1326. X                if (type == NOTES_D_M_Y) {    
  1327. X                    notesFound = FULL_OUTLINE;
  1328. X                }else if (type != NOTES_ALL_ALL_ALL) {    
  1329. X                    if (notesFound != FULL_OUTLINE) {
  1330. X                        notesFound = HALF_OUTLINE;
  1331. X                    }
  1332. X                }
  1333. X
  1334. X            }
  1335. X            free(untypedMsg);
  1336. X            thisMsg = strtok( NULL, "\n" );
  1337. X
  1338. X        }
  1339. X
  1340. X        free(notesBuffer);
  1341. X
  1342. X    }
  1343. X
  1344. X    if (hasWeeklyNotes == nowHasWeeklyNotes) {
  1345. X        for (row = 0; row < DATE_ROWS; row++) {
  1346. X            for (column = 0; column < DATE_COLS; column++) {
  1347. X                if (dayToShow == monthBoxes[row][column].date) {
  1348. X                    monthBoxes[row][column].boxOutline = notesFound;
  1349. X                    dateBoxDisplay(row, column, HIGHLIGHT);
  1350. X                }
  1351. X            }
  1352. X        }
  1353. X    }else{
  1354. X        monthDisplay();
  1355. X    }
  1356. X
  1357. X    notesModified = 1; 
  1358. X    hasWeeklyNotes = nowHasWeeklyNotes;
  1359. X
  1360. X}
  1361. X
  1362. int     stripType( oldMsg, newMsg, type )
  1363. X
  1364. char         *oldMsg;
  1365. char        **newMsg;
  1366. int             *type;
  1367. X
  1368. X{
  1369. X    int             i,j,
  1370. X                 typeFound, thisIsTypeChar;
  1371. X    *newMsg = (char *)malloc( strlen(oldMsg) + 1 );
  1372. X    if ( *newMsg  == (char *)0 ) {
  1373. X        fprintf(stderr, "Monthtool error:  Out of memory.\n");
  1374. X        exit(4);
  1375. X    }
  1376. X
  1377. X    i = 0;
  1378. X    typeFound = 0;
  1379. X
  1380. X    while ( *oldMsg != '\0' ) {
  1381. X        thisIsTypeChar = 0;
  1382. X        for (j = 0; j < NUM_NOTES_TYPE; j++) {
  1383. X            if ( *oldMsg == typeChar[j] ) {
  1384. X                *type = j;
  1385. X                thisIsTypeChar = 1;
  1386. X                typeFound = 1;
  1387. X            }
  1388. X        }            
  1389. X        if (thisIsTypeChar) {
  1390. X            oldMsg++;
  1391. X            while (*oldMsg == ' ') {
  1392. X                oldMsg++;
  1393. X            }
  1394. X        }else{
  1395. X            (*newMsg)[i] = *oldMsg;
  1396. X            oldMsg++;
  1397. X            i++;
  1398. X        }        
  1399. X    } 
  1400. X    (*newMsg)[i] = '\0';
  1401. X
  1402. X    if ( !typeFound ) {
  1403. X        *type = NOTES_D_M_Y;
  1404. X    }
  1405. X
  1406. X}
  1407. X
  1408. findTime(msg, time)
  1409. X
  1410. char     **msg;
  1411. int         *time;
  1412. X
  1413. X{
  1414. X    char     timeString[5];
  1415. X    char    *curChar;
  1416. X    int         timeFound;
  1417. X
  1418. X    curChar = *msg;                        
  1419. X    while (*curChar == ' ') {
  1420. X        curChar++;
  1421. X    }
  1422. X
  1423. X    if (strlen(curChar) >= 4) {        
  1424. X
  1425. X        timeFound = 1;
  1426. X        if (*(curChar+1) == ':') {
  1427. X            timeString[0] = '0';    
  1428. X        }else if (*(curChar+2) == ':') {
  1429. X            if (isdigit(*curChar)) {
  1430. X                timeString[0] = *curChar;
  1431. X                curChar++;
  1432. X            }else{
  1433. X                timeFound = 0;
  1434. X            }
  1435. X        }else{
  1436. X            timeFound = 0;
  1437. X        }
  1438. X
  1439. X        if (timeFound) {
  1440. X            if ( isdigit(*curChar) && isdigit(*(curChar+2)) && isdigit(*(curChar+3)) &&
  1441. X                    ( (*(curChar+4) == ' ') || (*(curChar+4) == '\0') ) ) {
  1442. X                timeString[1] = *curChar;
  1443. X                timeString[2] = *(curChar+2);
  1444. X                timeString[3] = *(curChar+3);
  1445. X                timeString[4] = '\0';                        
  1446. X            }else{
  1447. X                timeFound = 0;
  1448. X            }
  1449. X        }
  1450. X    }else{
  1451. X        timeFound = 0;
  1452. X    }
  1453. X
  1454. X    if (timeFound) {
  1455. X        *time = atoi( timeString );
  1456. X        if ( ( (int)(*time / 100) >= 24 ) || ( (*time % 100 ) >= 60 ) ) {
  1457. X            *time = 0;
  1458. X        }else{
  1459. X            curChar += 4;
  1460. X            while (*curChar == ' ') {
  1461. X                curChar++;
  1462. X            }
  1463. X            *msg = curChar;
  1464. X        }
  1465. X    }else{
  1466. X        *time = 0;
  1467. X    }
  1468. X                                         
  1469. X}
  1470. X
  1471. loadData()
  1472. X
  1473. X
  1474. X{
  1475. X    FILE                *fptr;
  1476. X
  1477. X    char                 basedata[MAX_MSG_LEN+100];
  1478. X    char                *timestr;
  1479. X    char                *apptstring;
  1480. X
  1481. X    int                     i;
  1482. X    struct apptsData     *new;
  1483. X
  1484. X
  1485. X    if ((fptr = fopen(toolFile, "r")) != NULL) {
  1486. X
  1487. X        for ( i = 0; i < (NUM_NOTES_TYPE + 1 /*for NOTES_ERROR*/); i++ ){
  1488. X            firstApptRecord[i] = lastApptRecord[i] = NULL;
  1489. X        }
  1490. X
  1491. X        while ((fgets(basedata, MAX_MSG_LEN+100, fptr) != NULL)) {
  1492. X
  1493. X            basedata[MAX_MSG_LEN+99] = NULL;
  1494. X
  1495. X            new = (struct apptsData *)malloc( sizeof( struct apptsData ) );
  1496. X            if ( new == (struct apptsData *)0 ) {
  1497. X                fprintf(stderr, "Monthtool error:  Out of memory.\n");
  1498. X                exit(4);
  1499. X            }
  1500. X
  1501. X            new->month = atoi( strtok(basedata, ",") );
  1502. X            new->day = atoi( strtok(NULL, ",") );
  1503. X            new->year = atoi( strtok(NULL, ",") );
  1504. X            new->dateNum = 10000 * new->year + 100 * new->month + new->day;
  1505. X
  1506. X            timestr = strtok(NULL,","); 
  1507. X            if (strcmp(timestr, "    ") == 0) {
  1508. X                new->time = 0;
  1509. X            }else{
  1510. X                new->time = atoi(timestr);
  1511. X            }     
  1512. X
  1513. X            apptstring = strtok(NULL, "\n" );
  1514. X            new->apptMsg = (char *)malloc(strlen(apptstring) + 1);
  1515. X            if ( new->apptMsg == (char *)0 ) {
  1516. X                fprintf(stderr, "Monthtool error:  Out of memory.\n");
  1517. X                exit(4);
  1518. X            }
  1519. X            strcpy(new->apptMsg, apptstring);
  1520. X
  1521. X            if ( new->year != 0 ) {
  1522. X                if ( new->month != 0 ) {
  1523. X                    if ( new->day != 0 ) {
  1524. X                        i = NOTES_D_M_Y;
  1525. X                    }else{
  1526. X                        i = NOTES_ERROR;    /* *mmyyyy */
  1527. X                    }
  1528. X                }else{
  1529. X                    i = NOTES_ERROR;        /* dd*yyyy or **yyyy */
  1530. X                }
  1531. X            }else{
  1532. X                if ( new->month == 99 ) {
  1533. X                    if ( (new->day >= 1) &&  (new->day <= 7) ) {
  1534. X                        i = NOTES_WEEKLY;
  1535. X                    }else{
  1536. X                        i = NOTES_ERROR;    
  1537. X                    }
  1538. X                }else if ( new->month != 0 ) {
  1539. X                    if ( new->day != 0 ) {
  1540. X                        i = NOTES_D_M_ALL;
  1541. X                    }else{
  1542. X                        i = NOTES_ERROR;    /* *mm* */
  1543. X                    }
  1544. X                }else{
  1545. X                    if ( new->day != 0 ) {
  1546. X                        i = NOTES_D_ALL_ALL;
  1547. X                    }else{
  1548. X                        i = NOTES_ALL_ALL_ALL;   
  1549. X                    }
  1550. X                }
  1551. X            }
  1552. X                
  1553. X            if ( i == NOTES_ERROR ) {
  1554. X                fprintf(stderr, "Monthtool warning! Invalid record: %u,%u,%4u,",
  1555. X                    new->month, new->day, new->year );
  1556. X                if (new->time != 0) {
  1557. X                    fprintf(stderr, "%04u", new->time);
  1558. X                }else{
  1559. X                    fprintf(stderr, "    ");
  1560. X                }
  1561. X                fprintf(stderr, ",%s\n", new->apptMsg );
  1562. X            }
  1563. X
  1564. X            insertApptRecord(new, i);
  1565. X                        
  1566. X        }
  1567. X
  1568. X        fclose(fptr);
  1569. X        stat( toolFile, &lastStatus );
  1570. X    }
  1571. X
  1572. X} 
  1573. X
  1574. insertApptRecord(new, type)
  1575. X
  1576. struct apptsData     *new;
  1577. int                     type;
  1578. X
  1579. X{
  1580. X    struct apptsData     *cur;
  1581. X    int                     inserted;
  1582. X
  1583. X    if (lastApptRecord[type] == NULL) {
  1584. X        firstApptRecord[type] = lastApptRecord[type] = new;
  1585. X        new->prev = NULL;                
  1586. X        new->next = NULL;    
  1587. X    }else{
  1588. X        inserted = 0;
  1589. X        cur = lastApptRecord[type];
  1590. X        do {
  1591. X            if (new->dateNum >= cur->dateNum) {
  1592. X                if (cur->next != NULL) {
  1593. X                    cur->next->prev = new;
  1594. X                }else{
  1595. X                    lastApptRecord[type] = new;
  1596. X                }
  1597. X                new->next = cur->next;
  1598. X                new->prev = cur;
  1599. X                cur->next = new;
  1600. X                inserted = 1;
  1601. X            }else{
  1602. X                cur = cur->prev;
  1603. X            }
  1604. X        } while ( !inserted && cur != NULL );
  1605. X        if (!inserted) {
  1606. X            new->next = firstApptRecord[type];
  1607. X            new->prev = NULL;
  1608. X            firstApptRecord[type]->prev = new;
  1609. X            firstApptRecord[type] = new;
  1610. X        }                        
  1611. X    }
  1612. X
  1613. X}
  1614. X
  1615. reloadData()
  1616. X
  1617. X
  1618. X{
  1619. X    struct stat            statusNow;
  1620. X
  1621. X
  1622. X    stat( toolFile, &statusNow );
  1623. X    if ( statusNow.st_mtime > lastStatus.st_mtime ) {
  1624. X        loadData();
  1625. X    }
  1626. X
  1627. X}
  1628. X
  1629. saveData()
  1630. X
  1631. X
  1632. X{
  1633. X    FILE                *fptr;
  1634. X
  1635. X    int                     i;
  1636. X    struct apptsData     *cur;
  1637. X
  1638. X
  1639. X    notesSave();
  1640. X
  1641. X    if (notesModified) {
  1642. X
  1643. X        if ((fptr = fopen(toolFile, "w")) == NULL) {
  1644. X            fprintf(stderr, "Monthtool error:  Cannot open %s file", toolFile);
  1645. X            return;
  1646. X        }
  1647. X
  1648. X        for ( i = 0; i < (NUM_NOTES_TYPE + 1 /*for NOTES_ERROR*/); i++ ) {
  1649. X            for (cur = firstApptRecord[i]; cur != NULL; cur = cur->next) {
  1650. X                fprintf(fptr, "%u,%u,%u,", cur->month, cur->day, cur->year );
  1651. X                if (cur->time != 0) {
  1652. X                    fprintf(fptr, "%04u", cur->time);
  1653. X                }else{
  1654. X                    fprintf(fptr, "    ");
  1655. X                }
  1656. X                if ( strlen(cur->apptMsg) > (MAX_MSG_LEN-1) ) {
  1657. X                    cur->apptMsg[MAX_MSG_LEN-1] = NULL;
  1658. X                    fprintf(stderr, "Monthtool warning! Record truncated: %u,%u,%4u,",
  1659. X                        cur->month, cur->day, cur->year );
  1660. X                    if (cur->time != 0) {
  1661. X                        fprintf(stderr, "%04u", cur->time);
  1662. X                    }else{
  1663. X                        fprintf(stderr, "    ");
  1664. X                    }
  1665. X                    fprintf(stderr, ",%s\n", cur->apptMsg );
  1666. X                }
  1667. X                fprintf(fptr, ",%s\n", cur->apptMsg );
  1668. X            }
  1669. X        }
  1670. X
  1671. X        fclose(fptr);
  1672. X        stat( toolFile, &lastStatus );
  1673. X
  1674. X        notesModified = 0;
  1675. X
  1676. X    }
  1677. X
  1678. X}
  1679. X
  1680. freeData()
  1681. X
  1682. X
  1683. X{
  1684. X
  1685. X    int                     i;
  1686. X    struct apptsData     *cur ;
  1687. X
  1688. X    for ( i = 0; i < (NUM_NOTES_TYPE + 1 /*for NOTES_ERROR*/); i++ ) {
  1689. X        while( firstApptRecord[i] != NULL) {
  1690. X            cur = firstApptRecord[i]; 
  1691. X            firstApptRecord[i] = firstApptRecord[i]->next;
  1692. X            free(cur->apptMsg);
  1693. X            free( cur );
  1694. X        }
  1695. X    }
  1696. X    
  1697. X}
  1698. X    
  1699. END_OF_FILE
  1700. if test 43509 -ne `wc -c <'monthtool.c'`; then
  1701.     echo shar: \"'monthtool.c'\" unpacked with wrong size!
  1702. fi
  1703. # end of 'monthtool.c'
  1704. fi
  1705. echo shar: End of archive 2 \(of 2\).
  1706. cp /dev/null ark2isdone
  1707. MISSING=""
  1708. for I in 1 2 ; do
  1709.     if test ! -f ark${I}isdone ; then
  1710.     MISSING="${MISSING} ${I}"
  1711.     fi
  1712. done
  1713. if test "${MISSING}" = "" ; then
  1714.     echo You have unpacked both archives.
  1715.     rm -f ark[1-9]isdone
  1716. else
  1717.     echo You still need to unpack the following archives:
  1718.     echo "        " ${MISSING}
  1719. fi
  1720. ##  End of shell archive.
  1721. exit 0
  1722.